package com.tongji.housediy.view.components
{
	import com.tongji.housediy.utils.ConstVariableInventory;
	import com.tongji.housediy.utils.DragDropManager;
	import com.tongji.housediy.vo.Goods;
	import com.tongji.housediy.view.components.NormalDoor;
	
	import flash.display.BitmapData;
	import flash.display.CapsStyle;
	import flash.display.GraphicsPath;
	import flash.display.GraphicsPathCommand;
	import flash.display.GraphicsSolidFill;
	import flash.display.GraphicsStroke;
	import flash.display.IGraphicsData;
	import flash.display.JointStyle;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	
	import mx.core.UIComponent;
	import mx.events.DragEvent;
	import mx.managers.DragManager;
	import mx.states.OverrideBase;
	
	/**
	 * 
	 * @author Bo Zhang
	 * 
	 */

	//移门
	public class ShiftDoor extends NormalDoor
	{
		private var graphicsData:Vector.<IGraphicsData>;
		private var stroke:GraphicsStroke;
		private var commands:Vector.<int>;
		
		private var wireFrameData:Vector.<Number>  = new Vector.<Number>();
		private var wireFrameGraphicsData:Vector.<IGraphicsData>;
		private var wireFrameStroke:GraphicsStroke;
		private var wireFrameCommands:Vector.<int>;
		
		public function ShiftDoor(newLength:Number, map:BitmapData, hostGoods:Goods)
		{
			this.typeIndex = 1;
			
			data = new Vector.<Number>();
			data.push(2, 0);
			data.push(2, newLength * 0.6);
			data.push(-2, newLength * 0.4);
			data.push(-2, newLength);
			
			super(newLength, map, hostGoods);
			
			this.dragType = "doorFormat";
			
			var solidFill:GraphicsSolidFill = new GraphicsSolidFill(0xFFFFFF);
			stroke = new GraphicsStroke(4, false, "normal", "none", JointStyle.MITER, 3, solidFill);
			
			commands = new Vector.<int>();
			commands.push(GraphicsPathCommand.MOVE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			commands.push(GraphicsPathCommand.MOVE_TO);
			commands.push(GraphicsPathCommand.LINE_TO);
			
			var wireFrameSolidFill:GraphicsSolidFill = new GraphicsSolidFill(0x56b765);
			wireFrameStroke = new GraphicsStroke(2, false, "normal", CapsStyle.SQUARE, JointStyle.MITER, 3, wireFrameSolidFill);
			
			wireFrameCommands = new Vector.<int>();
			wireFrameCommands.push(GraphicsPathCommand.MOVE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			wireFrameCommands.push(GraphicsPathCommand.LINE_TO);
			
			draw();
		}
		
		override public function clone():AbstractBorderChild
		{
			var newChild:ShiftDoor = new ShiftDoor(this.length, this.map ? this.map.clone() : null, this.hostGoods);
			newChild.selectedColorID = this.selectedColorID;
			newChild.selectedSizeID = this.selectedSizeID;
			return newChild;
		}
		
		override protected function draw():void
		{
			this.graphics.clear();
			
			var path:GraphicsPath = new GraphicsPath(commands, data);
			
			graphicsData = new Vector.<IGraphicsData>();
			graphicsData.push(stroke);
			graphicsData.push(path);
			
			this.graphics.drawGraphicsData(graphicsData);
			
			wireFrameData = new Vector.<Number>();
			wireFrameData.push(data[2] - 2, data[3]);
			wireFrameData.push(data[0] - 2, data[1]);
			wireFrameData.push(data[0] + 2, data[1]);
			wireFrameData.push(data[2] + 2, data[3]);
			wireFrameData.push(data[2] - 2, data[3]);
			wireFrameData.push(data[6] + 2, data[7]);
			wireFrameData.push(data[6] - 2, data[7]);
			wireFrameData.push(data[4] - 2, data[5]);
			wireFrameData.push(data[4] + 2, data[5]);
			
			var wireFramePath:GraphicsPath = new GraphicsPath(wireFrameCommands, wireFrameData);
			
			wireFrameGraphicsData = new Vector.<IGraphicsData>();
			wireFrameGraphicsData.push(wireFrameStroke);
			wireFrameGraphicsData.push(wireFramePath);
			
			this.graphics.drawGraphicsData(wireFrameGraphicsData);
		}
	}
}